//
// IntrGateManager.h
// Usage: Manage all `GATE' in the kernel
// Create Date: 2009-03-18
// Author: MaJiuyue
//
#ifndef _INTRGATE_MANAGER_H_
#define _INTRGATE_MANAGER_H_

#include "type.h"
#include "protect.h"
#include "const.h"
#include "handler.h"
#include "../core/Resource.h"

class CIntrGateManager : public Callable
{
private:
	GATE idt[IDT_SIZE];
	u8 idt_ptr[6];

public:
	/* Constructor */
	CIntrGateManager();

	/* Set gate descriptor property which has the index of `index' */
	void SetGateProperty(int index, u32 type, handler_type handler, u32 privilege);

	/* Enable maskable interrupt */
	void EnableInterrupt() { __asm__("sti"); }
	/* Disable maskable interrupt */
	void DisableInterrupt() { __asm__("cli"); }

	/* Enable IRQ */
	void EnableIRQ(u32 irq);
	/* Disable IRQ */
	void DisableIRQ(u32 irq);

private:
	/* Init the 8259A PIC chips */
	void init8259A();
	/* Init the 8253 clock chips */
	void init8253();
	/* Init the interrupt descriptor table */
	void initIDT();
};

#endif

